package Test;
import java.util.ArrayList;

import DBLayer.*;
import ModelLayer.*;

import org.junit.Before;
import org.junit.Test;

public class TestDBSalesOrder {
	private DBSalesOrder dbSalesOrder;
	private DBPartOrder dbPartOrder;
	private DBProduct dbProduct;
	private DBCustomer dbCustomer;
	private DBInvoice dbInvoice;
	
 
	@Before
	public void setUp() throws Exception {
		dbSalesOrder = new DBSalesOrder();
		dbPartOrder = new DBPartOrder();
		dbProduct = new DBProduct();
		dbCustomer = new DBCustomer();
		dbInvoice = new DBInvoice();
		
	}


	@Test
	public void testCreatePartOrder() throws Exception {
		
		int amount = 2;
		double partPrice = 1000.00;
		Product productId = dbProduct.searchProduct("CowboyderHat");
		int partOrderId = 1;
		SalesOrder salesOrderId = dbSalesOrder.searchSalesOrder(1);
		PartOrder po = new PartOrder(partOrderId, partPrice, productId, amount, salesOrderId);
		
		dbPartOrder.insertPartOrder(po);
		
	}
	
	@Test
	public void testUpdatePartOrder() throws Exception {
		int amount = 3;
		double partPrice = 1500.00;
		Product productId = dbProduct.searchProduct("CowboyderHat");
		int partOrderId = 1;
		SalesOrder salesOrderId = dbSalesOrder.searchSalesOrder(1);
		PartOrder po = new PartOrder(partOrderId, partPrice, productId, amount, salesOrderId);
		
		dbPartOrder.updatePartOrder(po);
	}
	
	@Test
	public void testCreateSalesOrder() throws Exception {
		int orderId = 1;
		String date = "12122012";
		double totalPrice = 1500;
		String deliveryStatus = "13122012";
		String deliveryDate = "14122012";
		double freightPrice = 0;
		boolean CODCharge = false;
		double discount = 0;
		Customer customerPhone = dbCustomer.getCustomerByName("Brian", false);
		ArrayList<PartOrder> po = new ArrayList<PartOrder>(); 
		po.add(dbPartOrder.searchPartOrder(1));
		Invoice invoiceNo = dbInvoice.getInvoiceNo(1);
		SalesOrder so = new SalesOrder(orderId, date, totalPrice, deliveryStatus, deliveryDate, freightPrice, CODCharge, discount, customerPhone, po, invoiceNo);
		
		dbSalesOrder.insertSalesOrder(so);
	}
	@Test
	public void testUpdateSalesOrder() throws Exception {
		int orderId = 1;
		String date = "12122012";
		double totalPrice = 1500;
		String deliveryStatus = "13122012";
		String deliveryDate = "15122012";
		double freightPrice = 0;
		boolean CODCharge = true;
		double discount = 0;
		Customer customerPhone = dbCustomer.getCustomerByName("Brian", false);
		ArrayList<PartOrder> po = new ArrayList<PartOrder>(); 
		po.add(dbPartOrder.searchPartOrder(1));
		Invoice invoiceNo = dbInvoice.getInvoiceNo(1);
		SalesOrder so = new SalesOrder(orderId, date, totalPrice, deliveryStatus, deliveryDate, freightPrice, CODCharge, discount, customerPhone, po, invoiceNo);
		
		dbSalesOrder.updateSalesOrder(so);
	}
	
		
	@Test
	public void testDeleteSalesOrderAndPartOrder() throws Exception{
		SalesOrder so = dbSalesOrder.searchSalesOrder(1);
		dbSalesOrder.deleteSalesOrder(so);
		PartOrder po = dbPartOrder.searchPartOrder(1);
		dbPartOrder.deletePartOrder(po);
	}
	

}
